package com.shopuser.controller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.shopuser.pojo.ShopUser;
import com.shopuser.service.ShopUserServiceI;

@Controller
@RequestMapping
public class ShopUserServlet  {
	@RequestMapping("/hello.do")
	public  String headRequest(Model model, String username, String password, String command){
		ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"spring.xml","spring-mybatis.xml"});
	 	ShopUserServiceI ui = (ShopUserServiceI)ac.getBean("userService");
		ShopUser user = new ShopUser(0,username,password);
		 
		//System.out.println("11");
//		model.addAttribute("price", password);
//		return "testttttt.jsp";
		switch (command) {
		case "login":
			String a = ui.login(user);
		if(a!=null){
			System.out.println("22");
			//ModelAndView ma = new ModelAndView("Welcome.html");
			//return "redirect:http://www.baidu.com";
			return "redirect:main.html";		
		}	
		case "regist":
			System.out.println("33");
			ui.addUser(user);
			return "redirect:login.html";
		
	}
		return command;
//	
	}
}
